package org.mags.object.common;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class FormattersCache {
	private List<FormatterBean> cache = new ArrayList<FormatterBean>();
	public void put(String pattern, Locale locale, Object formatter) {
		FormatterBean _formatter = new FormatterBean();
		_formatter.setPattern(pattern);
		_formatter.setLocale(locale);
		_formatter.setFormatter(formatter);
		cache.add(_formatter);
	}
	public Object get(String pattern, Locale locale) {
		return getFormatter(pattern, locale);
	}
	public Object getFormatter(String pattern, Locale locale) {
		for(FormatterBean i: cache.toArray(new FormatterBean[0]))
			if(i.getFormatter().equals(pattern)&&i.getLocale().equals(locale))
				return i;
		return null;
	}
}
